<template>
    <div>
        <h1>权益显示列表页</h1>
        <table>
            <thead>
                <tr>
                    <td>权益编号</td>
                    <td>权益名称</td>
                    <td>权益状态</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in data">
                    <td>{{a.QYId}}</td>
                    <td>{{a.QYName}}</td>
                    <td>{{a.QYState?"启用":"禁用"}}</td>
                    <td>
                        <input type="button" value="修改" @click="xiu(a.QYId)">
                    </td>
                    <td>
                        <input type="button" :value="a.QYState?'启用':'禁用'" @click="zhuangtai(a.QYId)">
                    </td>
                    <td>
                        <input type="button" value="删除" @click="shan(a.QYId)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <a href="/QYAdd">权益添加</a>
    <br>
    <a href="/hlist">会员显示列表</a> 
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
//实例化
const router=useRouter();
const route=useRoute();
const data=ref([ {
    "QYId": 0,
    "QYName": "",
    "QYState": ""
}]);
onMounted(()=>{
    getdata();
})
const shan=(val:any)=>{
    if(!confirm("您确定要删除吗？"))
    {
        return;
    }
    axios.delete("https://localhost:7258/api/QuanYi/QYDelete",{params:{id:val}}).then(res=>{
        if(res.data>0)
        {
            alert("删除成功");
            getdata();
        }
        else
        {
            alert("删除失败");
        }
    })
}
const zhuangtai=(val:any)=>{
    if(!confirm("您确定要修改状态吗？"))
    {
        return;
    }
    axios.delete("https://localhost:7258/api/QuanYi/QYStaet",{params:{id:val}}).then(res=>{
        if(res.data>0)
        {
            alert("状态修改成功");
            getdata();
        }
        else
        {
            alert("状态修改失败");
        }
    })
}
///修改
const xiu=(val:any)=>{
    if(!confirm("您确定要修改吗？"))
    {
        return;
    }
    router.push({path:"/xiu",query:{id:val}})
}
const getdata=()=>{
    axios.get("https://localhost:7258/api/QuanYi/QYShow").then(res=>{
        data.value=res.data;
    })
}












</script>

<style scoped>

</style>